﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dictionary.BusLayer
{
    class ModifyBus
    {
        //Ham them tu vung
        public static bool AddWord(string fn, string english, string phonetic, string vietnamese)
        {
            return DataLayer.ModifyWord.Add(fn, english, phonetic, vietnamese);
        }

        //Ham sua tu vung
        public static bool ModifyWord(string fn, string english, string phonetic, string vietnamese,string word)
        {
            return DataLayer.ModifyWord.Modify(fn, english, phonetic, vietnamese,word);
        }

        //Ham xoa tu vung
        public static bool DeleteWord(string fn, string word)
        {
            return DataLayer.ModifyWord.Delete(fn, word);
        }

        //Ham copy new image
        public static bool CopyImage(string folder, string fn, string word)
        {
            return DataLayer.FileDir.CopyToImage(folder,fn, word);
        }

        //Ham chep file anh, trong khi sua tu vung
        public static bool CopyModifyImage(string folder, string fn, string wordOld, string wordNew)
        {
            //Chep thanh 1 ten moi
            if (DataLayer.FileDir.CopyToImage(folder,fn, "tiduslmt9116") == false)
                return false;
            //Xoa file anh cu, neu co
            if (BusLayer.LibsContent.CheckExistImage(folder,wordOld + ".jpg") == true)
            {
                DataLayer.FileDir.DeleteFile(BusLayer.LibsContent.GetDirImage() + "\\" + folder + "\\" + wordOld + ".jpg");
            }
            else
                if (BusLayer.LibsContent.CheckExistImage(folder,wordOld + ".bmp") == true)
                {
                    DataLayer.FileDir.DeleteFile(BusLayer.LibsContent.GetDirImage() + "\\" + folder + "\\" + wordOld + ".bmp");
                }
                else
                    if (BusLayer.LibsContent.CheckExistImage(folder,wordOld + ".png") == true)
                    {
                        DataLayer.FileDir.DeleteFile(BusLayer.LibsContent.GetDirImage() + "\\" + folder + "\\" + wordOld + ".png");
                    }
            //Chep thanh ten moi
            if (DataLayer.FileDir.CopyToImage(folder, BusLayer.LibsContent.GetDirImage() + "\\" + folder + "\\" + "tiduslmt9116" + System.IO.Path.GetExtension(fn), wordNew) == false)
                return false;
            //xoa file anh tam
            if (DataLayer.FileDir.DeleteFile(BusLayer.LibsContent.GetDirImage() + "\\" +folder+"\\"+ "tiduslmt9116" + System.IO.Path.GetExtension(fn)) == false)
                return false;

            return true;
        }
    }
}
